package com.salt.admin.api.feign.hystrix;

import com.salt.admin.api.feign.client.UserClient;
import com.salt.admin.api.model.DataRule;
import com.salt.admin.api.model.Role;
import com.salt.admin.api.model.User;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description 用户（后台管理中心）远程调用失败处理类
 * @Author salt
 * @Date 2020/8/18 16:48
 * @Version 1.0
 */
@Slf4j
@Component
public class UserClientHystrix implements FallbackFactory<UserClient> {

    @Override
    public UserClient create(Throwable throwable) {

        String message = throwable.getMessage() == null ?
                "No available server for client: ADMIN-CENTER" :
                throwable.getMessage();
        log.info("Hystrix:{}", message);

        return new UserClient() {

            @Override
            public User getUser() {
                log.info("--获取当前用户信息异常");
                return null;
            }

            @Override
            public List<User> queryByIds(List<String> ids) {
                log.info("--根据ID的集合获取用户信息异常");
                return null;
            }

            @Override
            public User get(String id) {
                log.info("--根据ID查询用户信息异常, id: " + id);
                return null;
            }

            @Override
            public User getByUserName(String name) {
                log.info("--根据用户名查询用户信息异常, name: " + name);
                return null;
            }

            @Override
            public List<DataRule> getDataRuleList() {
                log.info("--获取数据规则异常");
                return null;
            }

            @Override
            public List<Role> getRoleList() {
                log.info("--获取角色异常");
                return null;
            }

            @Override
            public User getUserByLoginName(String loginName) {
                log.info("--根据登录名查询用户信息异常, loginName: " + loginName);
                return null;
            }

            @Override
            public List<User> findUserByOfficeId(String id) {
                log.info("--根据机构ID查询用户信息异常, ID: " + id);
                return null;
            }

            @Override
            public List<User> findList(User user) {
                log.info("--根据查询用户集合异常");
                return null;
            }

            @Override
            public List<String> getUserIdByRoleIds(List<String> roleIds) {
                log.info("--根据角色ID集合查询用户ID集合异常");
                return null;
            }

            @Override
            public User getByMobile(String mobile) {
                log.info("--根据手机号查询用户异常");
                return null;
            }
        };
    }
}
